<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\logic;

use app\common\model\UserAccount;
use think\Db;

/**
 * MobileArea逻辑
 */
class MobileArea extends LogicBase
{
    

    
    /**
     * 获取MobileArea列表
     */
    public function getMobileAreaList($where = [], $field = 'a.*', $order = 'sort desc')
    {
        
        $this->modelCountryMobileArea->alias('a');
        

        
        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];

        $count=$this->modelCountryMobileArea->where($where)->count();
        $this->modelCountryMobileArea->alias('a');
        return ['list'=>$this->modelCountryMobileArea->getList($where, $field, $order),'count'=>$count] ;
    }
    
    /**
     * 获取MobileArea列表搜索条件
     */
    public function getWhere($data = [])
    {
        
        $where = [];
        
        !empty($data['search_data']) && $where['a.country|a.area'] = ['like', '%'.$data['search_data'].'%'];
        
        return $where;
    }
    
    /**
     * MobileArea信息编辑
     */
    public function MobileAreaEdit($data = [])
    {
        
        $validate_result = $this->validateMobileArea->scene('edit')->check($data);
        
        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validateMobileArea->getError()];
        }
        
        $url = url('MobileAreaList');

        preg_match_all('/<img.*?src="(.*?)".*?\/?>/i', $data['content'], $out, PREG_PATTERN_ORDER);      //正则匹配img标签的src属性，返回二维数组
        if (!empty($out[1])) {
            foreach ($out[1] as $v) {
                    if(!preg_match('/http/',$v)){
                        $url1 = DMOAIN_URL.$v;
                        $data['content'] = str_replace($v, $url1, $data['content']);   //替换相对路径为绝对路径
                    }

            }
        }

        $result = $this->modelCountryMobileArea->setInfo($data);

        
        $handle_text = empty($data['id']) ? '新增' : '编辑';
        
        $result && action_log($handle_text, 'MobileArea' . $handle_text . '，title：' . $data['title']);
        
        return $result ? [RESULT_SUCCESS, 'MobileArea操作成功', $url] : [RESULT_ERROR, $this->modelCountryMobileArea->getError()];
    }

    /**
     * 获取MobileArea信息
     */
    public function getMobileAreaInfo($where = [], $field = 'a.*')
    {
        
        $this->modelCountryMobileArea->alias('a');
        

        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        
        return $this->modelCountryMobileArea->getInfo($where, $field);
    }
    


    /**

    
    /**
     * MobileArea删除
     */
    public function MobileAreaDel($where = [])
    {
        
        $result = $this->modelCountryMobileArea->deleteInfo($where);
        
        $result && action_log('删除', 'MobileArea删除，where：' . http_build_query($where));
        
        return $result ? [RESULT_SUCCESS, 'MobileArea删除成功'] : [RESULT_ERROR, $this->modelCountryMobileArea->getError()];
    }


    /**
     * 获取MobileArea列表
     */
    public function getWalletPriceList($where = [], $field = 'a.*', $order = 'sort desc')
    {

        $this->modelWalletPrice->alias('a');



        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];

        $count=$this->modelWalletPrice->where($where)->count();
        $this->modelWalletPrice->alias('a');
        return ['list'=>$this->modelWalletPrice->getList($where, $field, $order),'count'=>$count] ;
    }



}
